//
//  XMBrowseVideoCell.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/30.
//

#import "XMBrowseVideoCell.h"

@interface XMBrowseVideoCell ()

@property (nonatomic, strong) UIImageView *contentImgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *avatarImgView;
@property (nonatomic, strong) UILabel *userNameLabel;
@property (nonatomic, strong) UIImageView *likeImgView;
@property (nonatomic, strong) UILabel *numLabel;

@end

@implementation XMBrowseVideoCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    UIView *contentView = [[UIView alloc] initWithFrame:self.bounds];
    contentView.backgroundColor = kColorHEX(0xffffff);
    [contentView setCornerRadius:KScaleWidth(13.0)];
    [self addSubview:contentView];
    [contentView addSubview:self.contentImgView];
    [contentView addSubview:self.titleLabel];
    [contentView addSubview:self.avatarImgView];
    [contentView addSubview:self.userNameLabel];
    [contentView addSubview:self.likeImgView];
    [contentView addSubview:self.numLabel];
}

- (void)setContentWithBrowseProductModel:(XMMyBrowseProductModel *)productModel {
    [_contentImgView sd_setImageWithURL:[NSURL URLWithString:productModel.coverImageUrl]];
    _titleLabel.text = productModel.title;
    [_avatarImgView sd_setImageWithURL:[NSURL URLWithString:productModel.authorAvatar] placeholderImage:ImageNamed(@"mine_avatar_icon")];
    _userNameLabel.text = productModel.authorNickName;
    _numLabel.text = productModel.likeCount;
}

#pragma mark - Init
- (UIImageView *)contentImgView {
    if (!_contentImgView) {
        _contentImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, KScaleWidth(210.0))];
        [_contentImgView setPartCornerWithRectCorner:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadius:KScaleWidth(13.0)];
    }
    return _contentImgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(10.0), self.contentImgView.maxY + KScaleWidth(10.0), self.width - KScaleWidth(10.0)*2, KScaleWidth(22.0)) font:KFontSize(16.0) textColor:kColorHEX(0x333333)];
    }
    return _titleLabel;
}

- (UIImageView *)avatarImgView {
    if (!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(10.0), self.titleLabel.maxY + KScaleWidth(6.0), KScaleWidth(20.0), KScaleWidth(20.0))];
        [_avatarImgView setCornerRadius:_avatarImgView.height/2];
    }
    return _avatarImgView;
}

- (UILabel *)userNameLabel {
    if (!_userNameLabel) {
        _userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.avatarImgView.maxX + KScaleWidth(3.0), _avatarImgView.y, self.width/2 - _avatarImgView.maxX - KScaleWidth(3.0), _avatarImgView.height) font:KFontSize(12.0) textColor:kColorHEX(0x999999)];
    }
    return _userNameLabel;
}

- (UIImageView *)likeImgView {
    if (!_likeImgView) {
        _likeImgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.width - KScaleWidth(32.0) - KScaleWidth(12.5), self.userNameLabel.y, KScaleWidth(12.5), self.userNameLabel.height)];
        _likeImgView.contentMode = UIViewContentModeScaleAspectFit;
        _likeImgView.image = ImageNamed(@"evaluate_like_icon_select");
    }
    return _likeImgView;
}

- (UILabel *)numLabel {
    if (!_numLabel) {
        _numLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.likeImgView.maxX + KScaleWidth(4.0), _likeImgView.y, self.width - _likeImgView.maxX - KScaleWidth(4.0), _likeImgView.height) font:KFontSize(10.0) textColor:kColorHEX(0x999999)];
    }
    return _numLabel;
}

@end
